import random

class Investor(SimObject):


	def __init__(self) :
		self.IncomeTaxRate = 0
		self.RetirementSavingsRate = 0
		self.InitialSavings = 0
		self.PersonalSpendingRate = 0

		self.Properties = Simulation.InitializeList()
		self.PropertyIncome = Simulation.InitializeList()
		self.TotalIncome = Simulation.InitializeList()
		self.PersonalExpenses = Simulation.InitializeList()
		self.NetIncome = Simulation.InitializeList()
		self.Savings = Simulation.InitializeList()
		self.PropertyExpenses = Simulation.InitializeList()
		self.Job = Job(self)
		return self

	def Update(self) :
		m = Simulation.CurrentMonth

		self.Job.Update()

		# find tenants for vacant properties
		# update properties
		for property in self.Properties :
			if property.PurchaseMonth = m :
				continue
			if property.IsVacant() :
				self.FindTenant(property)
				
			# jack up rent after a year
			if not property.IsVacant() && (m - property.Tenant.StartMonth) % 12 == 0 :
				property.Tenant.MonthlyRent = (1+Economy.InflationRateYearly)*property.Tenant.MonthlyRent

			property.Update()
			self.PropertyIncome[m] +=  property.Income[m]

		self.TotalIncome[m] = self.PropertyIncome[m] + self.Job.MonthlyNetSalary[m]
		self.PersonalExpenses[m] = self.Job.MonthlyNetSalary * self.PersonalSpendingRate

	 	self.PayPropertyExpenses()

		self.NetIncome[m] = self.TotalIncome[m] - self.PersonalExpenses[m] - self.PropertyExpenses[m]

		if m == Simulation.StartMonth :
			self.Savings[m] = self.InitialSavings + self.NetIncome[m]
		else
			self.Savings[m] = self.Savings[m-1] + self.NetIncome[m]

		if self.RentalIncome[m] > self.Job.MonthlyNetSalary[m] * 1.1 :
			self.Job.Quit()
			print "Quit job at month " + str(m)

	def Finalize(self) :
		pass

	def FindTenant(self, property) :
		if random.random() > Economy.VacancyRate
			property.AddTenant(Economy.AverageMonthlyRent)
			
	def PayPropertyExpenses(self) :
		allocation = self.AllocateRentalIncome()
		for property in self.Properties :
			property.Mortgage.Pay(allocation[property])
			property.Expenses[m] += allocation[property]
			property.NetIncome[m] = property.Income[m] - property.Expenses[m]
			self.PropertyExpenses[m] += property.Expenses[m]

	def AllocateRentalIncome(self) :
		if self.Strategy == 1:
			pass
		elif self.Strategy == 2:
			pass
		elif self.Strategy == 3:
			pass
		# return dictionary
